<?php

class Country_Model_DbTable_Introducemedias extends Engine_Db_Table
{
  protected $_rowClass = 'Country_Model_Introducemedia';
  
  
  public function countMedia($country_id){
        $select = $this->select()
                       ->from($this->info('name'),"count(*) as total",null)
                       ->where('country_id = ?',$country_id);
        $row = $this->fetchRow($select);
        if (!$row) return 0;
        return $row->total;      
  }
  public function getPhotoSelect(array $params)
  {
    $select = $this->select();
    
    if( !empty($params['album']) && $params['album'] instanceof Album_Model_Album ) {
      $select->where('album_id = ?', $params['album']->getIdentity());
    } else if( !empty($params['album_id']) && is_numeric($params['album_id']) ) {
      $select->where('album_id = ?', $params['album_id']);
    }
    
    if( !isset($params['order']) ) {
      $select->order('order ASC');
    } else if( is_string($params['order']) ) {
      $select->order($params['order']);
    }
    
    return $select;
  }
  
  public function getPhotoPaginator(array $params)
  {
    return Zend_Paginator::factory($this->getPhotoSelect($params));
  }
}
